package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.TourCity;
import com.ruoyi.system.domain.TourGroupMember;
import com.ruoyi.system.domain.TourWorker;
import com.ruoyi.system.service.ITourGroupMemberService;
import com.ruoyi.system.service.ITourWorkerService;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("tourworker")
@ResponseBody
public class TourWorkerController extends BaseController {

    @Resource
    private ITourWorkerService workerService;

    @RequestMapping("/list")
    public AjaxResult list() {
        try {
            List<TourWorker> cities = workerService.selectWorkerList();
            return AjaxResult.success(cities);
        } catch (Exception e) {
//            e.printStackTrace();
            // 默认错误是500
            return AjaxResult.error("发生错误");
            // return error(AjaxResult.Type.WARN, "发生错误");
        }
    }

    @PostMapping("/create")
    public AjaxResult createWorker(@RequestBody TourWorker worker){
        try {
            int Result = workerService.createWorker(worker);
            System.out.println(Result);
            return AjaxResult.success(Result);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("发生错误");
        }
    }

    @PostMapping("/update")
    public AjaxResult updateWorker(@RequestBody TourWorker worker){
        try {
            workerService.updateWorker(worker);
            return AjaxResult.success();
        } catch (Exception e) {
            return AjaxResult.error("发生错误");
        }
    }
    @PostMapping("/delete")
    public AjaxResult deleteWorker(@RequestParam("id") int id){
        try {
            workerService.delectWorker(id);
            return AjaxResult.success();
        } catch (Exception e) {
            return AjaxResult.error("发生错误");
        }
    }
}
